﻿
using _03工厂方法设计模式;
using _03工厂方法设计模式.工厂方法反射;
/*---------------------begin-----------------------------*/
Console.WriteLine("工厂方法设计模式");
/*定义一个创建对象的接口，让子类决定实例化哪一个类*/

//现在情况是抽象依赖了细节，需要实现细节依赖抽象

Console.WriteLine("请输入操作数1");
var d1 = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("请输入操作数2");
var d2 = Convert.ToDouble(Console.ReadLine());

Console.WriteLine("请输入操作符");
string flag = Console.ReadLine();

ICalFactory? calFactory = null;

switch (flag)
{
    case "*":
        calFactory = new MulFactory();
        break;
    case "+":
        calFactory = new AddFactory();
        break;
    case "-":
        calFactory = new SubFactory();
        break;
    case "/":
        calFactory = new DivFactory();
        break;
}

ICalculator calculator=calFactory?.GetCalculator();
var result= calculator.GetResult(d1, d2);
Console.WriteLine(result);
//还是没有逃脱switch case
/*---------------------end-----------------------------*/
//方案2：通过反射处理 switch case

ReflectionFactory reflectionFactory = new ReflectionFactory();
ICalFactory calFactory2=  reflectionFactory.GetFac(flag);
 var result2= calFactory2.GetCalculator().GetResult(d1, d2);
Console.WriteLine(result2);